package com.store.app.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.store.app.R;
import com.store.app.bean.TaskLogBean;

import java.util.List;

/**
 * Created by Administrator on 2016/11/1.
 */

public class TaskLogAdapter extends BaseAdapter {
    private List<TaskLogBean> list;
    private Context context;

    public TaskLogAdapter(Context context, List<TaskLogBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {

        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Log.v("zyl","getView:"+position);
        Item item;
        if (convertView == null) {
            item = new Item();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_view, null);
            item.time = (TextView) convertView.findViewById(R.id.show_time);
            item.title = (TextView) convertView.findViewById(R.id.show_title);
            item.image = (TextView) convertView.findViewById(R.id.image);
            item.line = convertView.findViewById(R.id.line_normal);
            item.llContent = (LinearLayout) convertView.findViewById(R.id.ll_content);
        } else {
            item = (Item) convertView.getTag();
        }
        if(position==0){
            item.image.setBackgroundResource(R.drawable.pic_point_open);
        }else{
            item.image.setBackgroundResource(R.drawable.pic_point_close);
        }
        item.time.setText(list.get(position).getTime());
        item.title.setText(list.get(position).getTitle());

       // 最后一项时，竖线不再显示
        if (position == (list.size()-1)) {
            item.line.setVisibility(View.GONE);
        }else{
            item.line.setVisibility(View.VISIBLE);
        }
//        Log.v("zyl","view height:"+convertView.getLayoutParams().height);

        int time_height = item.time.getLayoutParams().height;
        int title_height = item.title.getLayoutParams().height;
        Log.v("zyl","得到的总高度："+(item.llContent.getLayoutParams().height));
//        ViewGroup.LayoutParams layoutParams1 = item.line.getLayoutParams();
//        layoutParams1.height = time_height+title_height+20;
//        item.line.setLayoutParams(layoutParams1);
        return convertView;
    }

    private class Item {
        TextView time, title;
        View line;
        TextView image;
        LinearLayout llContent;
    }


}
